<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="场站名称" prop="stationCode">
        <el-select v-model="queryParams.stationCode" placeholder="请选择场站" clearable>
          <el-option v-for="station in stationList" :key="station.chargeStationCode" :label="station.chargeStationName" :value="station.chargeStationCode" />
        </el-select>
      </el-form-item>
      <el-form-item label="预测日期" prop="forecastDate">
        <el-date-picker clearable v-model="queryParams.forecastDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择预测日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="container_ec">
      <czECharts :predictionList="predictionList" />
    </div>
    <el-table v-loading="loading" :data="predictionList" height="350">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="场站名称" align="center" prop="stationName" />
      <el-table-column label="预测时间" align="center" prop="time" />
      <el-table-column label="预测值" align="center" prop="value" />
      <el-table-column label="实际值" align="center" prop="reality" />
      <el-table-column label="包边值" align="center" prop="max" />
    </el-table>
  </div>
</template>

<script>
import { getStationInfo } from '@/api/smart/trendsDispatch/prediction'
import { listStation } from '@/api/smart/operator/station'
import czECharts from './ECharts/czECharts.vue'
export default {
  name: 'Prediction',
  components: { czECharts },
  data() {
    return {
      loading:false,
      // 显示搜索条件
      showSearch: true,
      // 场站功率预测表格数据
      predictionList: [],
      stationList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stationCode: null,
        forecastDate: this.getCurrentDate(),
        forecastValue: null
      }
    }
  },
  created() {
    this.getList()
    this.getStationAndDeviceList()
  },
  methods: {
    /** 查询场站功率预测列表 */
    getList() {
      this.loading = true
      this.queryParams.forecastDate=this.queryParams.forecastDate.slice(0, 10);
      getStationInfo(this.queryParams).then(response => {
        this.predictionList = response.data
        this.loading = false
      })
    },
    getCurrentDate() {
      let now = new Date();
      let year = now.getFullYear();
      let month = now.getMonth() + 1;
      let day = now.getDate();
      return year + "-" + month + "-" + day;
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        stationCode: null,
        forecastDate: null,
        forecastValue: null
      }
      this.resetForm('form')
    },
    /** 查询场站和模版列表 */
    async getStationAndDeviceList() {
      await listStation(this.queryParams).then(response => {
        this.queryParams.stationCode = response.rows[0].chargeStationCode
        this.stationList = response.rows
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryParams.stationCode = this.stationList[0].chargeStationCode
      this.handleQuery()
    }
  }
}
</script>
<style lang="scss" scoped>
.container_ec {
  width: 100%;
  height: 44vh;
  padding: 1vh 0;
}
</style>
